package drivers;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import nodes.NodeContainer;
import parser.FileParser;
import visualization.GuessConverter;
import analysis.Analyzer;

public class Visigoth {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		while(true)
		{
			System.out.println("Please input your parameters.");
			BufferedReader lineArguments = new BufferedReader(new InputStreamReader(System.in));
			String input = null;
			try {
				input = lineArguments.readLine();
			} catch (IOException ioe) {
				System.out.println("IO error trying to read input!");
				continue;
			}
			
			// Parse arguments
			String[] args2 = input.split(" ");
			Config config = new Config();
			config.parseArgumentsArr(args2);
			
			// Begin parsing the input file
			FileParser parser = new FileParser(config);
			boolean successfulParse = parser.parseFileFromPath();
			
			if(successfulParse) {
				// Analyze the nodes and select a subset based on the config criteria
				NodeContainer container = parser.getContainer();
				Analyzer analyzer = new Analyzer(config, container);
				analyzer.selectSubset();
				
				// Create output.gdf that can be visualized using GUESS
				GuessConverter converter = new GuessConverter(config);
				converter.convert(analyzer.getSubsetNodeContainer(), analyzer.getFocusNode());
				break;
			} else {
				System.err.println("ERROR: Unable to parse file. Exiting.");
				System.out.println(config.getUsage());
				continue;
			}
		}
		
	}

}